package com.tianji.mq.produce;

import com.tianji.common.constant.MqConstants;
import com.tianji.medical.pojo.PatientMedication;
import com.tianji.medical.service.MedicationSendLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Component
@RequiredArgsConstructor
@Slf4j
public class DoctorScheduleProduce {

    private final RocketMQTemplate rocketMQTemplate;


    public void sendCouponUpdateMessage(HashMap<String,Object> map) {
        try {
            rocketMQTemplate.convertAndSend(MqConstants.TOPIC, map);
            log.info("mq发送预约挂号信息成功");
        }catch (Exception e){
            //原因：消息发送失败：网络异常、RocketMQ 服务不可用等。
            log.info("mq发送预约挂号信息失败");
            //异步记录失败日志并且进入死信队列
            //medicationSendLogService.logFailedSend(patientMedication,e.getMessage());
            rocketMQTemplate.convertAndSend(MqConstants.TOPIC_DLQ, map);
        }
    }
}
